<?php
/**
 * @author: Gardennet
 * @date: 16-12-15
 * @email: lwp8800@sina.com
 */
namespace App\Services\Wechat;

use App\Services\Wechat\sdk\MpWechat;

class WechatConfigService
{
    public $public_config;
    public $open_config;

    public function setPublicConfig($config = [])
    {
        $this->public_config = $config;
    }

    public function getPublicConfig()
    {
        empty($this->public_config)?$this->public_config = config('wechat')['wechatPublic']:$this->public_config;
        return $this->public_config;
    }

    public function setOpenConfig($config = [])
    {
        $this->open_config = $config;
    }

    public function getOpenConfig()
    {
        empty($this->open_config)?$this->open_config = config('wechat')['wechatOpen']:$this->open_config;
        return $this->open_config;
    }

    /**
     * 获取微信配置
     *
     * $config['appid'];
     * $config['secret'];
     * $config['token']
     * $config['encodingAesKey']
     *
     * @return MpWechat
     * @throws \Exception
     */
    public function getWechatPublicObject()
    {
        $_config['type'] = 'wechatPublic';
        $_config['data'] = $this->getPublicConfig();
        return new MpWechat($_config);
    }

    /**
     * 获取微信开放平台配置
     *
     * $config['componentAppid'];
     * $config['componentSecret'];
     * $config['componentToken']
     * $config['componentEncodingAesKey']
     *
     * @return MpWechat
     * @throws \Exception
     */
    public function getWechatOpenObject()
    {
        $_config['type'] = 'wechatOpen';
        $_config['data'] = $this->getOpenConfig();
        return new MpWechat($_config);
    }
}